package orbito.ui;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.HashMap;
import java.util.Map;

public class InputStore implements MouseListener, KeyListener {
	
	static Map<Integer, Boolean> keysPressed;
	static Map<Integer, Boolean> buttonsPressed;
	
	public static void init() {
		InputStore.keysPressed = new HashMap<Integer, Boolean>();
		InputStore.buttonsPressed = new HashMap<Integer, Boolean>();
	}
	
	public static void keyPressed(int keyCode) {
		keysPressed.put(keyCode, true);
	}
	
	public static void keyReleased(int keyCode) {
		keysPressed.put(keyCode, false);
	}
	
	public static boolean isKeyPressed(int keyCode) {
		if (keysPressed.containsKey(keyCode))
			return keysPressed.get(keyCode);
		return false;
	}
	
	public static void buttonPressed(int buttonCode) {
		buttonsPressed.put(buttonCode, true);
	}
	
	public static void buttonReleased(int buttonCode) {
		buttonsPressed.put(buttonCode, false);
	}
	
	public static boolean isButtonPressed(int buttonCode) {
		if (buttonsPressed.containsKey(buttonCode))
			return buttonsPressed.get(buttonCode);
		return false;
	}

	public void mouseClicked(MouseEvent e) { }
	public void mouseEntered(MouseEvent e) { }
	public void mouseExited(MouseEvent e) { }
	
	public void mousePressed(MouseEvent e) {
		buttonPressed(e.getButton());
	}
	
	public void mouseReleased(MouseEvent e) {
		buttonReleased(e.getButton());
	}
	
	public void keyPressed(KeyEvent e) {
		keyPressed(e.getKeyCode());
	}
	
	public void keyReleased(KeyEvent e) {
		keyReleased(e.getKeyCode());
	}
	
	public void keyTyped(KeyEvent e) { }
}
